package com.surfilter.thread;

import com.surfilter.gsxt.crawler.RefereeGsxtCollectUtil;
import com.surfilter.gsxt.util.FileWriteUtils;
import com.surfilter.pojo.GsxtTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ResourceBundle;

/**
 * GsxtThread
 * Created by grom on 2017/4/19.
 */
public class GsxtThread implements Runnable{
    private static Logger logger = LoggerFactory.getLogger(GsxtThread.class);
    private static String destDir = ResourceBundle.getBundle("system-config").getString("dest_dir");
    private GsxtTask task;

    public GsxtThread(GsxtTask task) {
        super();
        this.task = task;
    }
    public void run() {
        try {
            RefereeGsxtCollectUtil util = new RefereeGsxtCollectUtil();
            util.openBrowser();
            //整个页面的源码
            String result = util.xywCrawler(task);
            util.closeBrowser();
            if(null != result) FileWriteUtils.writeToFileByLine(result,destDir,task.getCompanyName());
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("采集线程发生异常");
        }
    }
}